function addConfig(){
	window.location.href = "addemailconfig.jsp";
}

$(function(){
	InitTable();
});

//请求数据  
function InitTable() { 
    $.ajax({
    	type : 'get',
		dataType: 'json',
		contentType: "application/json",
        url: '/meileche/admin/con.do?action=2',      //提交到一般处理程序请求数据  
        success: function(data) {
			$.each(data, function(index, value){
				$("#tableHeader").after(getInfoForTable(value.mailServerHost,value.mailServerPort,value.email,value.A1,value.id));
			});
        }  
    });              
}

function deletes(id){
	if(!confirm("确定要删除邮件配置吗？")){
		return;
	}
	$.ajax({
    	type : 'get',
		dataType: 'text',
		contentType: "application/json",
        url: '/meileche/admin/con.do?action=4&keyId='+id,      //提交到一般处理程序请求数据  
        success: function(data) {
			if(data == "1"){
				location.reload();
			}else{
				layer.alert('删除失败', 2);
			}
        }  
    }); 
}

function forbis(id){
	$.ajax({
    	type : 'get',
		dataType: 'text',
		contentType: "application/json",
        url: '/meileche/admin/con.do?action=1&mark=0&keyId='+id,      //提交到一般处理程序请求数据  
        success: function(data) {
			if(data == "1"){
				location.reload();
			}else{
				layer.alert('禁用失败', 2);
			}
        }  
    }); 
}


function starts(id){
	$.ajax({
    	type : 'get',
		dataType: 'text',
		contentType: "application/json",
        url: '/meileche/admin/con.do?action=1&mark=1&keyId='+id,      //提交到一般处理程序请求数据  
        success: function(data) {
			if(data == "1"){
				location.reload();
			}else{
				layer.alert('启用失败', 2);
			}
        }  
    }); 
}

function emailModule(){
	window.location.href="emailModule.jsp";
}
function details(id){
	window.location.href = "emailconfigdetail.jsp?id="+ id;
}

function getInfoForTable(mailServerHost,mailServerPort,email,a1,id){
	var str = "<tr>";
	str +="<td style=\"color: #444;\">"+mailServerHost+"</td>";
	str +="<td style=\"color: #444;\">"+mailServerPort+"</td>";
	str +="<td style=\"color: #444;\">"+email+"</td>";
	str +="<td style=\"color: #444;\"><a style=\"cursor:pointer;\" onclick=\"deletes('"+id+"');\"><img src=\"../image/delete.jpg\"/></a><a><img src=\"../image/edit.png\"/></a><a style=\"cursor:pointer;\" onclick=\"details('"+id+"')\"><img src=\"../image/detail.png\"/></a>";
	if(a1 == "1"){
		str +="<a style=\"cursor:pointer;\" onclick=\"forbis('"+id+"');\"><img src=\"../image/can.jpg\"/></a></td>";
	}else{
		str +="<a style=\"cursor:pointer;\" onclick=\"starts('"+id+"');\"><img src=\"../image/forbi.jpg\"/></a></td>";
	}
	str +="</tr>";
		
	return str;
}